import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Line
from pyecharts.globals import ThemeType
df = pd.read_excel('全国人口年度数据.xlsx', index_col=0)
df = df.iloc[:, ::-1]
line = Line(init_opts=opts.InitOpts(
    width='1200px', height='600px', theme=ThemeType.INFOGRAPHIC, page_title='面积图'
))
line.add_xaxis(xaxis_data=['第一季度','第二季度','第三季度','第四季度'])
line.add_yaxis(series_name='2020年', y_axis=df.loc[0,0:4], areastyle_opts=opts.AreaStyleOpts(opacity=0.5))
line.add_yaxis(series_name='2021年', y_axis=df.loc[0,4:8], areastyle_opts=opts.AreaStyleOpts(opacity=0.5))
line.add_yaxis(series_name='2022年', y_axis=df.loc[0,8:12], areastyle_opts=opts.AreaStyleOpts(opacity=0.5))
line.set_global_opts(
    title_opts=opts.TitleOpts(
        title='2003-2022年全国年末总人口、城镇人口和乡村人口折线图',
        pos_left='center'),
    yaxis_opts=opts.AxisOpts(name='全国居民人均可支配收入（元）', name_location='centter', nema_gap=55, in_=6000),
    legend_opts=opts.LegendOpts(pos_tight='10%', pos_top='8%')
line.render('例7-2.html')